<template>
	<view class="house-list">
		<view v-for="(houses , i ) in housesList" :key="i">
			<view class="houses-item" @click="gotoDetail(houses)">
				<!-- 房屋左侧图标区域 -->
				<view class="houses-item-left">
					<image :src="getSrc(houses.houseTypeImage)" class="houses-pic"></image>
				</view>
				<!-- 房屋右侧信息区域 -->
				<view class="houses-item-right">
					<view class="top-title">
						<text class="onsale">{{getStatus(houses.saleStatus)}}</text>
						<text class="slogan">户型：{{houses.estateType}}</text>
					</view>
					<view class="houses-name">{{houses.building}}栋{{houses.unit}}单元{{houses.num}}号</view>

					<view class="houses-info">建筑面积{{houses.constructionArea}}m²
					</view>
					<!-- <view class="houses-price"></view> -->
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				queryObj: {
					"pageNum": 1.,
					"pageSize": 10,
					"queryBean": {
						businessId: uni.getStorageSync('estateId')
					},
				},
				housesList: [],
				total: 0,
				//是否正在请求数据
				isLoading: false
			};
		},
		onLoad(options) {
			// this.queryObj.queryBean = options.queryBean || {}
			this.getHouseList()
		},
		methods: {
			getStatus(status) {
				switch (status) {
					case 1:
						return "未售"
						break;
					case 2:
						return "在售"
						break;
					default:
						return '已售'
						break;
				}
			},
			getSrc(ids) {
				if (typeof ids == undefined || ids == null || ids == '') {
					return
				}
				let idArray = ids.split(',')
				let id = idArray[0]
				if ((typeof id) != undefined && id != '') {
					let _src = uni.$http.baseURL + '/file/download?fileId=' + id
					return _src
				}
			},
			getStatue(status) {
				switch (status) {
					case 1:
						return '未售'
						break;
					case 2:
						return '在售'
						break;
					case 3:
						return '已售'
						break;
				}
			},
			async getHouseList(cb) {
				this.isLoading = true
				const {
					data: res
				} = await uni.$http.post(uni.$http.baseURL + '/estateManage/getEstateInfoList', this.queryObj)
				cb && cb()

				if (res.status == 0) {
					this.isLoading = false
					//数据请求完毕，使用回调关闭下拉刷新
					// if (res.meta.status !== 200) return uni.$showMsg()
					this.housesList = [...this.housesList, ...res.body.data]
					this.total = res.body.totalSize
				} else {
					uni.$showMsg(res.message)
				}
			},
			//触底事件
			onReachBottom() {
				//判断是否还有下条数据
				if (this.queryObj.pageSize * this.queryObj.pageNum >= this.total) return uni.$showMsg('已加载完所有数据！')
				//节流
				if (this.isLoading) return
				this.queryObj.pageNum += 1
				this.getHouseList()
			},
			//下拉刷新时间
			onPullDownRefresh() {
				this.queryObj.pageNum = 1
				this.total = 0
				this.isLoading = false
				this.housesList = []
				this.getHouseList(() => uni.stopPullDownRefresh())
			},
			//点击跳转到商品详情页
			gotoDetail(item) {
				console.log(item)
				uni.setStorageSync('houseId', item.estateId)
				uni.navigateTo({
					url: '/mainpkg/house_zone_detail/house_zone_detail'
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.house-list {
		padding-top: 20rpx;
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
	}

	.houses-item {
		display: flex;
		// margin: 20rpx 30rpx 0 30rpx;
		padding: 20rpx;
		width: 620rpx;
		background-color: #FFFFFF;
		border-radius: 20rpx;
		margin-bottom: 20rpx;
		.houses-item-left {
			.houses-pic {
				border-radius: 20rpx;
				width: 200rpx;
				height: 200rpx;
				display: block;
			}
		}

		.houses-item-right {
			margin-left: 40rpx;
			font-family: PingFang SC;
			display: flex;
			justify-content: space-between;
			flex-direction: column;

			.top-title {
				display: flex;
				flex-direction: row;

				.onsale {
					background: linear-gradient(90deg, #E93423 0%, #FB6858 100%);
					border-radius: 4rpx;
					font-size: 20rpx;
					font-weight: 500;
					color: #FFFFFF;
					width: 60rpx;
					height: 30rpx;
					text-align: center;
				}

				.slogan {
					margin-left: 17rpx;
					font-size: 24rpx;
					font-weight: 500;
					color: #333333;
				}
			}

			.houses-name {
				font-size: 28rpx;
				font-weight: bold;
				color: #333333;
			}

			.houses-info {
				font-size: 24rpx;
				font-weight: 500;
				color: #999999;
				width: 400rpx;
				overflow: hidden;
				/* #ifndef APP-NVUE */
				white-space: nowrap;
				text-overflow: ellipsis;
				/* #endif */
				/* #ifdef APP-NVUE */
				lines: 1;
				text-overflow: ellipsis;
				/* #endif */
			}

			.houses-price {
				font-size: 28rpx;
				font-weight: bold;
				color: #E62129;
			}
		}
	}
</style>
